/**
 * 
 */
package com.zxc.utils;

import java.io.File;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import cn.hutool.core.io.FileUtil;

/**
 * @author ThinkPad
 *
 */
public class FileTest {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
//		testNginxlog();
		
		testNginxlog1();
		
		String projectPath = System.getProperty("user.dir");
        System.out.println("项目部署路径为：" + projectPath);
	}

	public static void testNginxlog1() {
		List<String> list = FileUtil.readLines("E:\\kmty.log", "UTF-8");
		
		List<String> result = new ArrayList<String>();
		for (String string : list) {
			String[] arr = StringUtils.split(string, " ");
			if(NumberUtils.toDouble(arr[13]) >= 10) {
				result.add(string);
			}
		}
		
		FileUtil.writeLines(result, new File("E:\\kmty.log.1"), "UTF-8");
	}
	
	public static void testNginxlog() {
		List<String> list = FileUtil.readLines("E:\\kmty.log", "UTF-8");
		
		int ge5 = 0;
		int ge7 = 0;
		for (String string : list) {
			String[] arr = StringUtils.split(string, " ");
			if(NumberUtils.toDouble(arr[13]) >= 5) {
				ge5++;
			}
			if(NumberUtils.toDouble(arr[13]) >= 7) {
				ge5++;
			}
		}
		System.out.println("总数："+list.size());
		System.out.println("大于5秒："+ge5+",占比："+(ge5/list.size()*100)+"%");
		System.out.println("大于7秒："+ge7+",占比："+(ge7/list.size()*100)+"%");
	}
	
	public static void testLog() {
		List<String> list = FileUtil.readLines("E:\\73251567336455260.txt", "UTF-8");
		List<JSONObject> log3 = new ArrayList<JSONObject>();
		List<JSONObject> log4 = new ArrayList<JSONObject>();
		List<JSONObject> log5 = new ArrayList<JSONObject>();
		List<JSONObject> log6 = new ArrayList<JSONObject>();
		List<JSONObject> log7 = new ArrayList<JSONObject>();
		List<JSONObject> log8 = new ArrayList<JSONObject>();
		List<JSONObject> log9 = new ArrayList<JSONObject>();
		List<JSONObject> log10 = new ArrayList<JSONObject>();
		List<JSONObject> log11 = new ArrayList<JSONObject>();
		List<JSONObject> log12 = new ArrayList<JSONObject>();
		List<JSONObject> log13 = new ArrayList<JSONObject>();
		List<JSONObject> log14 = new ArrayList<JSONObject>();
		List<JSONObject> log15 = new ArrayList<JSONObject>();
		
		for (String string : list) {
			
			JSONObject o = JSONObject.parseObject(string);
			switch (o.getIntValue("logType")) {
			case 3:
				log3.add(o);
				break;
			case 4:
				log4.add(o);		
				break;
			case 5:
				log5.add(o);
				break;
			case 6:
				log6.add(o);
				break;
			case 7:
				log7.add(o);
				break;
			case 8:
				log8.add(o);
				break;
			case 9:
				log9.add(o);
				break;
			case 10:
				log10.add(o);
				break;
			case 11:
				log11.add(o);
				break;
			case 12:
				log12.add(o);
				break;
			case 13:
				log13.add(o);
				break;
			case 14:
				log14.add(o);
				break;
			case 15:
				log15.add(o);
				break;
			}
		}
		
		Comparator<JSONObject> c = (o1,o2) ->{
			return o1.getJSONObject("data").getIntValue("routeId") - o2.getJSONObject("data").getIntValue("routeId");
		};
		
		log8.sort(c);
		log9.sort(c);
		log10.sort(c);
		log11.sort(c);
		log12.sort(c);
		log13.sort(c);
		log14.sort(c);
		log15.sort(c);
		
		System.out.println(JSON.toJSON(log3));
		System.out.println(JSON.toJSON(log4));
		System.out.println(JSON.toJSON(log5));
		System.out.println(JSON.toJSON(log6));
		System.out.println(JSON.toJSON(log7));
		System.out.println(JSON.toJSON(log8));
		System.out.println(JSON.toJSON(log9));
		System.out.println(JSON.toJSON(log10));
		System.out.println(JSON.toJSON(log11));
		System.out.println(JSON.toJSON(log12));
		System.out.println(JSON.toJSON(log13));
		System.out.println(JSON.toJSON(log14));
		System.out.println(JSON.toJSON(log15));
	}
	
}
